# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def levelOrder(self, root):
        """
        :type root: TreeNode
        :rtype: List[List[int]]
        """
        if not root:
            return []
        a = [(root, 0)]
        b = []
        while a:
            node, level = a.pop(0)
            if len(b) < level + 1:
                b.insert(level, [])
            b[level].append(node.val)
            if node.left:
                a.append((node.left,level+1))
            if node.right:
                a.append((node.right,level+1))
        return b

m = TreeNode(1)
m.left = TreeNode(2)


m1 = TreeNode(1)
m1.left = TreeNode(2)
m1.right = TreeNode(3)

s = Solution()

t = s.levelOrder(m1)
print(t)


